import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { ValidateEnglish } from "@/utils/validate";

/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  name: [
    { required: true, message: "工号名称为必填项", trigger: "blur" },
    { max: 50, message: "工号名称不能超过50字", trigger: "blur" }
  ],
  begin: [{ required: true, message: "工号起始为必填项", trigger: "blur" }],
  current: [{ required: true, message: "当前工号为必填项", trigger: "blur" }],
  next: [{ required: true, message: "下一工号为必填项", trigger: "blur" }],
  prefix: [
    { max: 10, message: "工号前缀不能超过10字", trigger: "blur" },
    {
      trigger: "blur",
      validator: (_, value, callback) => {
        if (ValidateEnglish(value) || !value) {
          callback();
        } else {
          callback(new Error("工号前缀只能使用英语"));
        }
      }
    }
  ],
  suffix: [
    { max: 10, message: "工号后缀不能超过10字", trigger: "blur" },
    {
      trigger: "blur",
      validator: (_, value, callback) => {
        if (ValidateEnglish(value) || !value) {
          callback();
        } else {
          callback(new Error("工号前缀只能使用英语"));
        }
      }
    }
  ],
  description: [{ max: 200, message: "工号描述不能超过200字", trigger: "blur" }]
});
